<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
	orgId=userInfo.getOrgId().toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>新增文章栏目</title>
		<%@ include file="../../../common/Admin-list.jsp"%>  
		<script type="text/javascript" src="<%=bpath %>Scripts/jquery/jquery.form.js"></script> 		 
		 
		<script type="text/javascript">	
		$(function(){
			$("#sortID").numeral();   //只能输入数字
			
			// 组织机构						
			$('#fk_orgId').combotree({
				 url: '../district/findByPidAll.json',			
				 panelHeight:'300', 
	             editable: true ,      
	             onClick: function (node) { 
	            	$("#orgIdName").val($("#fk_orgId").combotree("getText"));	            	
	           	 }, //全部折叠               
	           	 onLoadSuccess: function (node, data) {	           			           		 
	           		 $('#fk_orgId').combotree('tree').tree("collapseAll"); 
	             }
			});
			if(<%=orgId %>!=null){ //是否管理员
				$("#fk_orgId").combotree("setValue",<%=orgId %>);	
				$("#fk_orgId").combotree('disable');
			}
			
			$('#noOrgId').click(function(){
				$('#fk_orgId').combotree('clear');
			});			
			
			
			if(<%=orgId %>==null){ //如果是管理员
				//所有科室
				$('#ALLOrgId').click(function(){				
					$("#fk_orgId").combotree("setValue","-99");	
					$("#orgIdName").val("所有科室");
				});
				
				//添加其他栏目文章
				var categoryUrl='../ArticleCategory/getEasyUiTreeForSelect.json?';
				$('#url').combotree({				
					 url:categoryUrl, //开放投稿
					 valueField: 'id',
		             textField: 'text',
		             editable: false ,//可编辑--定义用户是否可以直接输入
		             onLoadSuccess: function (node, data) {                     
		             }
				});
			}
			
			
			// 父类			
			$('#parentID').combotree({
				 url: '../ArticleCategory/getEasyUiTreeForSelect.json?noAdmin=yes', 
				 valueField: 'id',
	             textField: 'text',
	             editable: false ,//可编辑--定义用户是否可以直接输入             
	             onClick: function (node) { 	      	            	 	            	 
	            	 $("#levelID").val(Number(node.attributes.levelID)+1);
	            	 if(node.attributes.fk_orgId!=null){
	            		 $('#fk_orgId').combotree('setValue', node.attributes.fk_orgId);
	            	 }else{
	            		 $('#fk_orgId').combotree('clear');
	            	 }	            	 
	             }, //全部折叠               
	             onLoadSuccess: function (node, data) {        
	              // $('#parentID').combotree('tree').tree("collapseAll"); 
	             }
			});	
		
			var subUrl="../ArticleCategory/save.json";			
			if('${data.type}'!=null&&'${data.type}'=="edit"){ //修改				
				$("#lblTitle").html('修改文章栏目');			
				if('${data.articleCategory.visible}'=="0"){
					$("#visible").attr("checked",false);
				}
				$("#id").val('${data.articleCategory.id}');				
				$("#name").val('${data.articleCategory.name}');		
				$("#levelID").val('${data.articleCategory.levelID}');		
				$('#parentID').combotree('setValue', '${data.articleCategory.parentID}');			
				$('#fk_orgId').combotree('setValue', '${data.articleCategory.fk_orgId}'); 					
				
				if('${data.articleCategory.is_contribute}'=="1"){
					$("#is_contribute").attr("checked",true);
				}
				
				if(<%=orgId %>==null){ //是否管理员								
					$("#url").combotree("setValues",'${data.articleCategory.url}');	
				}
				// $("#code").val('${data.articleCategory.code}');
				
				$("#sortID").val('${data.articleCategory.sortID}');				
				subUrl="../ArticleCategory/update.json";
			}else if('${data.type}'!=null&&'${data.type}'=="addSub"){ //新增子集	
				var newLevel=Number('${data.levelID}')+1;
				$("#lblTitle").html('新增第'+newLevel+'级类目');
				$('#parentID').combotree('setValue', '${data.parentID}');				
				$("#levelID").val(newLevel);				
				if('${data.fk_orgId}'!='null'){
					$('#fk_orgId').combotree('setValue', '${data.fk_orgId}');
				}				
				
			}else if('${data.type}'!=null&&'${data.type}'=="add"){ //$('.easyui-combotree').combotree("clear")
				$("#lblTitle").html('新增一级类目');				
				$('#parentID').combotree('setValue', '${data.parentID}');
			}			
					
			//保存
			$("#lnbSave").click(function(){	
				if($("#fk_orgId").combotree("getValue")!='-99'){
					$("#orgIdName").val($("#fk_orgId").combotree("getText"));					
				}else{
					$("#orgIdName").val('所有科室');		
				}
				 
				$("#addForm").ajaxSubmit({
					url:subUrl,
					type:"POST",
					beforeSubmit:checkForm,
					contentType:"application/x-www-form-urlencoded;charset=UTF-8",
					error:function(){},
					success:function(data){
						if(data.success==true){
							showTip("保存成功，返回列表页面！","succeed");					    	
						}else{
							//showTip("操作失败","warning");  
							art.dialog.alert('保存失败，请确认填写正确！');
						}
					},
				});
				
			});
			
		});
			
		function checkForm(){			
			var flag=$('#addForm').form('validate');
			return flag;
		}
				
		//消息提示  
		function showTip(mess,icon) {  
		    art.dialog({  
		        id : 'Tip',  
		        title : '消息',  
		        fixed : true,  
		        lock : true,  
		        opacity: .2,  
		        content : mess,  
		        icon : icon,  
		        time : 1  
		    });  
		    setTimeout('originReload()', 1000);  
		}  
		
		//重载来源页面  
		function originReload(){  
		    var win = art.dialog.open.origin;		    
		    win.location.reload();  
		}	
		
		</script>
		
</head>
<body>
<div>
	<div id="tab">
        <ul>
            <li class="Current">
            	<a href="#" onfocus="this.blur()">
            		<span id="lblTitle" > 新增文章类目  </span>
            	</a>
            </li>
        </ul>
    </div>  
    <div id="menu">
        <ul>
            <li>
            	<a id="lnbSave">
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/save.gif" alt="Save" />保存</span>
            	</a>
            </li>
        </ul>
    </div>   
    
    <div id="middle"> 
    <form action="../ArticleCategory/save.json" id="addForm" name="addForm" method="post" >   
    <div class="editor">
        <table class="eTable">
        	<tr class="eTr">
                <td class="name">                         	         
                </td>
                <td>	
                	 <input id="visible" type="checkbox" name="visible" checked="checked" value="1" />
                	 <label for="visible">网站显示</label>
                	 &nbsp;&nbsp;&nbsp;&nbsp;                	 
                	 <input id="is_contribute" type="checkbox" name="is_contribute"  value="1" />
                	 <label for="is_contribute">开放投稿</label>
				</td>
            </tr> 
        	<tr class="eTr">
                <td class="name">          
                	<label>上一级</label>               	         
                </td>
                <td>	
                	<select id="parentID" name="parentID"   class="easyui-combotree" style="width:250px;"></select>                
				</td>
            </tr>
            <tr class="eTr">
                <td class="name">
                    <label id="Label2" >所属科室</label></td>
                <td>
                	
                	<select id="fk_orgId" name="fk_orgId" class="easyui-combotree"  style="width:250px;"></select>
                	<%if(null==orgId){%> 
                	&nbsp;&nbsp;<label id="noOrgId" style="color:blue;">取消选择</label>                	
                	                	
                	&nbsp;&nbsp;<label id="ALLOrgId" style="color:pink;">所有科室</label>
                	<%} %>
                	<input id="orgIdName" name="orgIdName" type="hidden" ></input>
                </td>
            </tr>                        
            <tr class="eTr">
                <td class="name">
                    <label id="Label2" >类目名称</label>
                    <font color="red">*</font>
                </td>
                <td>
                    <input id="name" name="name" required="true" class="easyui-validatebox validatebox-text input"></input>  
                    <input id="id" name="id" type="hidden"></input>                                     
                    <input id="levelID" name="levelID" type="hidden" value="1" ></input> 
                </td>
            </tr>    
            <tr class="eTr">
                <td class="name">
                    <label id="Label5" >导航排序</label></td>
                <td>
                    <input id="sortID" name="sortID" class="input" ></input>
                </td>
            </tr>      
            <%if(null==orgId){%> 
            <tr class="eTr">
                <td class="name">
                    <label id="Label4">添加其他栏目文章</label></td>
                <td>
                    <!--<input id="url" name="url" class="input"></input>  -->
                    <select id="url" name="url" class="easyui-combotree" multiple style="width:250px;"></select>					
					
                </td>
            </tr>
            <%}%>                       
            <!--  
            <tr class="eTr">
                <td class="name">
                    <label id="Label2" >编码</label>
                </td>
                <td>
                    <input id="code" name="code" class="input" ></input>                    
                </td>
            </tr>            
            <tr class="eTr">
                <td class="name">
                    <label id="Label4">导航路径</label></td>
                <td>
                    <input id="url" name="url" class="input"></input>
                </td>
            </tr>  -->             
        </table>
        
    </div>
    </form> 
    </div>
</div>
</body>
</html>